package com.learn.lock.vol;

/**
 * @author : Yu.Tan
 * @date : 2023/5/9 15:10
 * @desc : **
 */
public class TestVolatile {
    private static volatile Boolean stop = false;

    /**
     * 实现可见性
     * @param args
     */
    public static void main(String[] args) {
        new Thread(() -> {
            while (!stop) {
            }
            System.out.println(Thread.currentThread() + " not stopped");
        }).start();

        try {
            Thread.sleep(1000);
            System.out.println(Thread.currentThread() + " after 1 seconds");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        stop = true;
    }
}
